<template>
<div class="body">
    <div>
      <NavBar
  title="党支部书记排名"
/>
    </div>
    <el-table :data="list">
       <el-table-column label="排名" align="center">
        <template slot-scope="scope">
          {{scope.$index+1}}
        </template>
      </el-table-column>
        <el-table-column label="姓名"  prop="姓名"></el-table-column>
      
        <el-table-column label="得分"  prop="得分"></el-table-column>
     </el-table>
</div>
</template>
<script>
import request from "../../utils/request"
import linq from "linq"
import NavBar from "../../components/NavBar/navBar";
export default {
    data(){
        return {
            list:[],
            user:{},
            loading:false,
        }
    },
     components: {
    NavBar
  },
    async mounted(){
        this.loading=true;
       var teachers  = await request({url:'/teacher',method:'get',params:{query:{role:'参评党支书'}}})
      var performances  = await request({url:'/performance',method:'get',
            params:{
                query:{年份:'2019',cate:"党支部书记评价"}}
            })
        teachers.data.forEach(teacher=>{

          var performance =  linq.from(performances.data).firstOrDefault(e=>e.姓名==teacher.name);
         
          if(performance){
  
          var score = linq
            .from(performance.评分记录)
         
            .orderByDescending("$.score")
            .skip(3).orderBy("$.score")
            .skip(3).average("$.score");
          score = isNaN(score) ? 0 : score;
              linq.from(performance.评分记录)
            
              performance.得分 = score.toFixed(2);
            this.list.push(performance);
          }else{
             this.list.push({姓名:teacher.name,得分:0});
          }
       
       })
       
      this.list = linq.from(this.list).orderByDescending("$.得分").toArray();
      this.loading= false;
    },
}
</script>